<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>localStorage</title>
    </head>
    <body>
        <button onclick="saveCar()">向local中存入一个对象</button>
        <button onclick="readCar()">向local中读取一个对象</button>
        <button onclick="removeCar()">向local中读取一个对象</button>
        <button onclick="deleteCar()">向local中读取一个对象</button>

        <script>
            let car = {
                brand: '奔驰',
                age:2,
                price:200000
            }
            // 增
            function saveCar (){
                localStorage.setItem('car',JSON.stringify(car));
            }

            // 查
            function readCar() {
               const result =  localStorage.getItem('car');
               console.log(JSON.parse(result));
            }

            // 改 
            function removeCar() {
                localStorage.removeItem('car');
            }

            // 删
            function deleteCar() {
                localStorage.clear();
            }
        </script>
    </body>
</html>